package com.yuntsg.ruiijn.paperana.test;

import com.aspose.words.*;
import com.baomidou.mybatisplus.annotation.TableField;
import com.yuntsg.ruiijn.databse_search.entity.FileDetails;
import common.extractText.Change;
import lombok.SneakyThrows;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static common.util.ExtractUtil.getLocalLicense;

/**
 * @Author: gcr
 * @Date: 2023/10/7 15:53
 */
public class WordSp {
    @SneakyThrows
    public static void main(String[] args) {

        Integer rid = 1;
        getLocalLicense();

        Document doc = null;
        try {
            doc = new Document("D:\\Users\\GCR\\Desktop\\ss.doc");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        SectionCollection sections = doc.getSections();

        List<FileDetails> fileDetailsArr = new ArrayList<FileDetails>();
        StringBuffer bf = new StringBuffer();


        for (Section section : sections) {
            ParagraphCollection paragraphs = section.getBody().getParagraphs();
            for (Paragraph paragraph : paragraphs) {
                String text = paragraph.getRange().getText();
                bf.append(text);
            }
        }

        List<TableField> tableList = new ArrayList<>();
        String s = bf.toString();

        List<String> strList = Arrays.asList(s.split("\r"));
        if (strList.size() <= 1) {
            //进行多句子拆分
            if (s.contains(".")) {
                strList = Arrays.asList(s.split("\\."));
            }

        }

        List<Change.TableField> ex = Change.ex(strList);
        for (Change.TableField tableField : ex) {
            FileDetails fileDetails = new FileDetails();
            fileDetails.setFId(rid);
            fileDetails.setTpye(1);
            fileDetails.setParagraphName(tableField.getParagraph_name());
            fileDetails.setSubProject(tableField.getSub_project());
            fileDetails.setSegment(tableField.getParagraph());
            fileDetails.setSentence(tableField.getSentence());
            // 如果这里 动态匹配会不会影响入库时间, 直接在先获取吧 要不这里如果一个大文本入库容易卡时间
            fileDetails.setTxtContent(tableField.getStr());
            fileDetailsArr.add(fileDetails);
        }

        System.out.println(fileDetailsArr);
    }
}
